﻿using System;
using UnityEngine;

namespace UniRx.Operators
{
	// Token: 0x020003ED RID: 1005
	internal class FrameTimeIntervalObservable<T> : OperatorObservableBase<TimeInterval<T>>
	{
		// Token: 0x06001499 RID: 5273 RVA: 0x0005D004 File Offset: 0x0005B404
		public FrameTimeIntervalObservable(IObservable<T> source, bool ignoreTimeScale) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
			this.ignoreTimeScale = ignoreTimeScale;
		}

		// Token: 0x0600149A RID: 5274 RVA: 0x0005D020 File Offset: 0x0005B420
		protected override IDisposable SubscribeCore(IObserver<TimeInterval<T>> observer, IDisposable cancel)
		{
			return this.source.Subscribe(new FrameTimeIntervalObservable<T>.FrameTimeInterval(this, observer, cancel));
		}

		// Token: 0x04000BF0 RID: 3056
		private readonly IObservable<T> source;

		// Token: 0x04000BF1 RID: 3057
		private readonly bool ignoreTimeScale;

		// Token: 0x020003EE RID: 1006
		private class FrameTimeInterval : OperatorObserverBase<T, TimeInterval<T>>
		{
			// Token: 0x0600149B RID: 5275 RVA: 0x0005D035 File Offset: 0x0005B435
			public FrameTimeInterval(FrameTimeIntervalObservable<T> parent, IObserver<TimeInterval<T>> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
				this.lastTime = ((!parent.ignoreTimeScale) ? Time.time : Time.unscaledTime);
			}

			// Token: 0x0600149C RID: 5276 RVA: 0x0005D068 File Offset: 0x0005B468
			public override void OnNext(T value)
			{
				float num = (!this.parent.ignoreTimeScale) ? Time.time : Time.unscaledTime;
				float num2 = num - this.lastTime;
				this.lastTime = num;
				this.observer.OnNext(new TimeInterval<T>(value, TimeSpan.FromSeconds((double)num2)));
			}

			// Token: 0x0600149D RID: 5277 RVA: 0x0005D0C0 File Offset: 0x0005B4C0
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x0600149E RID: 5278 RVA: 0x0005D0F8 File Offset: 0x0005B4F8
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000BF2 RID: 3058
			private readonly FrameTimeIntervalObservable<T> parent;

			// Token: 0x04000BF3 RID: 3059
			private float lastTime;
		}
	}
}
